//
// Created by Administrator on 2025/4/20.
//

#ifndef TEST_CONNECTIONPOOL_H
#define TEST_CONNECTIONPOOL_H

#include <queue>
#include <mutex>
#include <atomic>
#include <memory>
#include <thread>
#include <functional>
#include <condition_variable>
#include "Connection.h"


class ConnectionPool {
public:
    static ConnectionPool * getInstance();
    std::shared_ptr<Connection> getConnection();
private:
    ConnectionPool();
    ~ConnectionPool();
    bool loadConf();
    void produceConnTask();
private:
    const char * m_host;
    const char * m_username;
    const char * m_password;
    const char * m_db;
    unsigned int m_port;

    int m_init_size;
    int m_max_size;
    int m_min_size;
    int m_conn_timeout;

    std::queue<Connection*> m_conn_queue;
    std::mutex m_mutex;
    std::condition_variable m_cond;
    std::atomic_int m_active_num;

    const char * m_conf_filename;
};


#endif //TEST_CONNECTIONPOOL_H
